import React, { Component } from 'react';
//解释loadable原理
const Loadable = ({ loader, loading: Loading }) => {
  return class LoadableComponent extends Component {
    state = {
      LoadableComponent: null
    };
    componentDidMount() {
      //导致render再次执行
      loader().then(res => {
        this.setState({
          LoadableComponent: res.default
        });
      }); //引入组件
    }
    render() {
      let { LoadableComponent } = this.state;
      return LoadableComponent ? <LoadableComponent /> : <Loading />;
    }
  };
};
export default Loadable;
